package com.example.springbootdeom.contrlloer;

import com.example.springbootdeom.entity.Course;
import com.example.springbootdeom.entity.Student;
import com.example.springbootdeom.service.StudentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController

public class StudentController{

    @Resource
    private StudentService studentService;

    //查询个人信息(id)
    @GetMapping("getStudent.action")
    public Student getAll(int id){
        Student student = studentService.getstudent(id);
        return student;
    }

    //修改个人信息
    @PostMapping("updateMsg.action")
    public String updateMsg(Student student){

        String uname=student.getUname();
        String password=student.getPassword();
        int id=student.getId();
        System.out.println(student);
       if(studentService.updateMsg(student))
       {
           return "ok";
       }
       return "error";

    }

    //选课
    @GetMapping("addCourse.action")
    public String addCourse(int stuID,int couserID){
        if(studentService.addCourse(stuID,couserID)){
            return "ok";
        }else {
            return "error";
        }

    }

    //查看个人选课列表
    @GetMapping("listcourse.action")
    public List<Course> getall(int id){
        List<Course> list=studentService.getAllCourse(id);
        if (list !=null){
            return list;
        }else {
            return null;
        }
    }




}
